|
|
|
| |
|
|
|
|
Notice that in the code example you declare a variable, set the variable to a value, and then set the data control property with the variable. This could all be done in a single line of code. Here's an example: |
|
|
|
|
|
|
|
|
Data1.DatabaseName= C:\TYSDBVB5\SOURCE\DATA\BOOKS5.MDB" |
|
|
|
|
|
|
|
|
By declaring variables and using those variables to set properties, you'll create a program that is easier to understand and modify in the future. |
|
|
|
|
|
|
|
|
|
|
When you set the DatabaseName property, you are telling Visual Basic the database you are using. However, at this point, Visual Basic does not know what data table you want to use with the data control. Use the RecordSource property to indicate the data table you want to access. |
|
|
|
|
|
|
|
|
Now, modify the OpenDB procedure you created earlier by adding code that sets the RecordSource property of the data control to access the Authors data table. Be sure to declare a variable, initialize it to the correct table, and then use the variable to set the data control property. When you are finished, your procedure should look like the one shown in the following code example: |
|
|
|
|
|
|
|
|
Public Sub OpenDB()
Dim cDBName As String ' declare a string variable
Dim cTblName As String ' declare a string variable
'
cDBName = "c:\tysdbvb5\source\data\books5.mdb" ' point to database
cTblName = "Authors" ' point to authors table
'
Data1.DatabaseName = cDBName ' set database property
Data1.RecordSource = cTblName ' set recordsource property
'
Data1.Refresh ' update data control properties
End Sub |
|
|
|
|
|
|
|
|
Before you get too far into the project, you should save your work. Save the form as BNDCTRL1.FRM and the project as BNDCTRL.VBP. |
|
|
|
|
|
|
|
|
Setting the ReadOnly and Exclusive Properties |
|
|
|
|
|
|
|
|
There are two more data control properties that you'll need to set in this example: ReadOnly and Exclusive. The ReadOnly and Exclusive properties are Boolean (True/False) properties that you can use to limit access to the database. When you set the Exclusive property to True, you are opening the database for your use only. In other words, no one else can open the database (or any of the tables in the database) while you have it open. This is handy when you want to perform major updates or changes to the database and do not want anyone else in the file at the same time. |
|
|
|
|
|